//
//  BCTableViewController.m
//  BCVersion
//
//  Created by 吴 崧 on 14-2-23.
//  Copyright (c) 2014年 Jungle. All rights reserved.
//

#import "BCTableViewController.h"
#import "BCLoginViewController.h"
@interface BCTableViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation BCTableViewController



-(instancetype)initWithDataSource:(NSArray *)dataSource
                       CellHeight:(CGFloat)cellHeight
                     FooterHeight:(CGFloat)footerHeight
                     HeaderHeight:(CGFloat)headerHeight
                          KeyWord:(NSString *)keyWord;
{
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        _dataSource = dataSource;
        _nextStart = 0;
        _limit = SearchLimit;
        _defaultCellHeight = cellHeight;
        _defaultFooterHeight = footerHeight;
        _defaultHeaderHeight = headerHeight;
        _keyWord = keyWord;
        _selectCellNeedLogin = YES;
     
    }
    return self;
}

-(void)loadView
{
    [super loadView];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];


     self.tableView.delegate = self;
    self.tableView.dataSource = self;
}


-(void)addEgoFresh
{
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [self createCellWithReuseIndentifier:CellIdentifier];
    }
    // Configure the cell...
    [self tableView:tableView configCell:cell forClient:(NSObject *)[self.dataSource objectAtIndex:indexPath.row] atIndexPath:indexPath];
    return cell;

}


- (UITableViewCell*)createCellWithReuseIndentifier:(NSString *)reuseIdentifier
{
    UITableViewCell* cell = [self loadCellFromNib:nil];
    
    
    return cell;
}

- (UITableViewCell *)loadCellFromNib:(NSString *)name {
	return [[NSBundle mainBundle] loadNibNamed:name owner:nil options:nil][0];
}

- (void)tableView:(UITableView *)tableView configCell:(UITableViewCell *)cell forClient:(NSObject *)client atIndexPath:(NSIndexPath *)indexPath{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
	if (self.dataSource.count > 0) {
		return _defaultFooterHeight;
	} else {
		return 0;
	}
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	return _defaultCellHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
	return _defaultHeaderHeight;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_selectCellNeedLogin) {
        if (USER_MANAGER.didLogin) {
            [self tableView:tableView didSelectClient:[self.dataSource objectAtIndex:indexPath.row]];
        }else
        {
            [BCLoginViewController show];
            
        }
    }
	;
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)tableView:(UITableView *)tableView didSelectClient:(NSObject *)client {
    
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here, for example:
    // Create the next view controller.
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];

    // Pass the selected object to the new view controller.
    
    // Push the view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
}
 
 */

@end
